/* 
 * signal.h
 * This file has no copyright assigned and is placed in the Public Domain.
 * This file is a part of the clang port package.
 * No warranty is given; refer to the file DISCLAIMER within the package.
 *
 * A way to set handlers for exceptional conditions (also known as signals).
 *
 */

#ifndef	_CLANG_PORT_SIGNAL_H_
#define	_CLANG_PORT_SIGNAL_H_

/* All the headers include this file. */
#ifndef __IMPL_CLANG_PORT_API_
#	include <_clang_port.h>
#else
#	include <include/_clang_port.h>
#endif

#ifndef __IMPL_CLANG_PORT_API_
/*
 * The actual signal values. Using other values with signal
 * produces a SIG_ERR return value.
 *
 * NOTE: SIGINT is produced when the user presses Ctrl-C.
 *       SIGILL has not been tested.
 *       SIGFPE doesn't seem to work?
 *       SIGSEGV does not catch writing to a NULL pointer (that shuts down
 *               your app; can you say "segmentation violation core dump"?).
 *       SIGTERM comes from what kind of termination request exactly?
 *       SIGBREAK is indeed produced by pressing Ctrl-Break.
 *       SIGABRT is produced by calling abort.
 * TODO: The above results may be related to not installing an appropriate
 *       structured exception handling frame. Results may be better if I ever
 *       manage to get the SEH stuff down.
 */
#define	SIGINT		2	/* Interactive attention */
#define	SIGILL		4	/* Illegal instruction */
#define	SIGFPE		8	/* Floating point error */
#define	SIGSEGV		11	/* Segmentation violation */
#define	SIGTERM		15	/* Termination request */
#define SIGBREAK	21	/* Control-break */
#define	SIGABRT		22	/* Abnormal termination (abort) */

#define NSIG 23     /* maximum signal number + 1 */

#ifndef _SIG_ATOMIC_T_DEFINED
typedef int sig_atomic_t;
#define _SIG_ATOMIC_T_DEFINED
#endif

/*
 * The prototypes (below) are the easy part. The hard part is figuring
 * out what signals are available and what numbers they are assigned
 * along with appropriate values of SIG_DFL and SIG_IGN.
 */

/*
 * A pointer to a signal handler function. A signal handler takes a
 * single int, which is the signal it handles.
 */

/*
 * These are special values of signal handler pointers which are
 * used to send a signal to the default handler (SIG_DFL), ignore
 * the signal (SIG_IGN), indicate an error return (SIG_ERR),
 * get an error (SIG_SGE), or acknowledge (SIG_ACK).
 */
#define	SIG_DFL	((__p_sig_fn_t) 0)
#define	SIG_IGN	((__p_sig_fn_t) 1)
#define	SIG_ERR ((__p_sig_fn_t) -1)
#define SIG_SGE ((__p_sig_fn_t) 3)
#define SIG_ACK ((__p_sig_fn_t) 4)

#endif // __IMPL_CLANG_PORT_API_

typedef	void (*__p_sig_fn_t)(int);

#ifdef	__cplusplus
extern "C" {
#endif
/* 
 * Clang port Api.
*/

	typedef __p_sig_fn_t CLANG_PORT_FPTR_TYPE(signal)(int, __p_sig_fn_t);
	extern CLANG_PORT_FPTR_VAR(signal);
	typedef int CLANG_PORT_FPTR_TYPE(raise)(int);
	extern CLANG_PORT_FPTR_VAR(raise);

#ifndef __IMPL_CLANG_PORT_API_
/*
 * STD C Api.
 */
CLANG_PORT_INLINE __p_sig_fn_t signal(int sig, __p_sig_fn_t,pFn)
{
	return CLANG_PORT_CALL_FPTR(signal)(sig,pFn);
}
CLANG_PORT_INLINE int raise(int sig)
{
	return CLANG_PORT_CALL_FPTR(raise)(sig);
}
#endif /* __IMPL_CLANG_PORT_API_ */

#ifdef	__cplusplus
}
#endif


#endif	/* Not _CLANG_PORT_SIGNAL_H_ */

